package edu.vista;

import com.sun.lwuit.Command;
import com.sun.lwuit.Graphics;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;

import edu.logica.util.Constantes;

public class FormResultado extends Formulario {

    private Command atras;
    private Image lienzo, result;
    private Graphics pincel;

    public FormResultado(Image result) {
        super();
        this.result = result;
        setTitle("Resultado");
        atras = new Command("Atras");
        addCommand(atras);
        setCommandListener(this);
    }

    public void paint(Graphics g) {
        super.paint(g);
//        for (int i = 0; i < getComponentCount(); i++) {
//            System.out.println(getComponentAt(i) + "  " + i);
//            System.out.println(getComponentAt(i).getHeight() + "  Height");
//            System.out.println(getComponentAt(i).getWidth() + "  Width");
//        }
        if (lienzo == null) {
            lienzo = Image.createImage(getWidth(), getHeight() - getComponentAt(2).getHeight());
            pincel = lienzo.getGraphics();
        }
        if (result != null) {
            pincel.drawImage(result,(getWidth() / 2) - (result.getWidth() / 2),  ((getHeight()-getComponentAt(0).getHeight()) / 2) - (result.getHeight() / 2));
        } else {
            pincel.drawString("No hay resultados disponibles", getComponentAt(0).getHeight(), 10);
        }
        g.drawImage(lienzo, 0, 0);

    }

    public void destruir() {
        super.destruir();

    }

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() instanceof Command) {
            if (((Command) e.getSource()).equals(atras)) {
                AdminIntefaz.getAdminIntefaz().adelante = false;
                AdminIntefaz.getAdminIntefaz().setCurrent(
                        Constantes.MENSAJE);

            }

        }

    }
}
